import { getGoodsInfo } from '@/api/home'
import {
  auditFail,
  auditSuccess,
  checkGoodsDetail,
  checkUserDes,
  checkUserId,
  checkUserName,
  getAllGoodsInfo,
  getConditionSheetsWhereOnStateIsOne,
  updatePV,
  selectConditionSheetOperationData
} from '@/api/mall'
import { buyGoods } from '@/api/purchase'

const goods = {
  actions: {
    displayGoods () {
      return new Promise((resolve, reject) => {
        getGoodsInfo().then(response => {
          resolve(response)
        }).catch(error => {
          reject(error)
        })
      })
    },
    displayAllgoods () {
      return new Promise((resolve, reject) => {
        getAllGoodsInfo().then(response => {
          resolve(response)
        }).catch(error => {
          reject(error)
        })
      })
    },
    CheckGoodsDetail ({ commit }, checkInfo) {
      const commodityId = checkInfo.commodityId
      return new Promise((resolve, reject) => {
        checkGoodsDetail(commodityId).then(response => {
          commit('')
          resolve(response)
        }).catch(error => {
          reject(error)
        })
      })
    },
    CheckUserName ({ commit }, checkInfo) {
      const commodityId = checkInfo.commodityId
      return new Promise((resolve, reject) => {
        checkUserName(commodityId).then(response => {
          commit('')
          resolve(response)
        }).catch(error => {
          reject(error)
        })
      })
    },
    CheckUserDes ({ commit }, checkInfo) {
      const commodityId = checkInfo.commodityId
      return new Promise((resolve, reject) => {
        checkUserDes(commodityId).then(response => {
          commit('')
          resolve(response)
        }).catch(error => {
          reject(error)
        })
      })
    },
    CheckUserId ({ commit }, checkInfo) {
      const commodityId = checkInfo.commodityId
      return new Promise((resolve, reject) => {
        checkUserId(commodityId).then(response => {
          commit('')
          resolve(response)
        }).catch(error => {
          reject(error)
        })
      })
    },
    UpdatePV ({ commit }, checkInfo) {
      const commodityId = checkInfo.commodityId
      return new Promise((resolve, reject) => {
        updatePV(commodityId).then(response => {
          commit('')
          resolve(response)
        }).catch(error => {
          reject(error)
        })
      })
    },
    selectConditionSheetOperationData({ commit }, checkInfo) {
      return new Promise((resolve, reject) => {
        selectConditionSheetOperationData(checkInfo).then(response => {
          commit('')
          resolve(response)
        }).catch(error => {
          reject(error)
        })
      })
    },
    buyGoods ({ commit }, checkInfo) {
      const commodityId = checkInfo.commodityId
      const userId = checkInfo.userId
      const goodsPrice = checkInfo.goodsPrice
      return new Promise((resolve, reject) => {
        buyGoods(commodityId, userId, goodsPrice).then(response => {
          commit('')
          resolve(response)
        }).catch(error => {
          reject(error)
        })
      })
    },
    getConditionSheetsWhereOnStateIsOne(){
      return new Promise((resolve, reject) => {
        getConditionSheetsWhereOnStateIsOne().then(response => {
          resolve(response)
        }).catch(error => {
          reject(error)
        })
      })
    },
    auditSuccess ({ commit }, auditInfo){
      const conditionSheetId = auditInfo.conditionSheetId
      const commodityName = auditInfo.commodityName
      const commodityDescription = auditInfo.commodityDescription
      const commodityPrice = auditInfo.commodityPrice
      return new Promise((resolve, reject) => {
        auditSuccess(conditionSheetId, commodityName, commodityDescription, commodityPrice).then(response => {
          commit('')
          resolve(response)
        }).catch(error => {
          reject(error)
        })
      })
    },
    auditFail ({ commit }, auditInfo){
      const conditionSheetId = auditInfo.conditionSheetId
      return new Promise((resolve, reject) => {
        auditFail(conditionSheetId).then(response => {
          commit('')
          resolve(response)
        }).catch(error => {
          reject(error)
        })
      })
    }
  }
}
export default goods
